package game.views;

import game.data.XlsData;
import hx.assets.BitmapDataFuture;
import game.worlds.GameWorld;
import game.shader.HeadShader;
import game.views.RoleLogView.RoleLogData;
import hx.display.Box;

/**
 * 角色日志渲染组件
 */
@:build(hx.macro.UIBuilder.build("assets/views/RoleLogItem.xml"))
class RoleLogItem extends Box {
	public function setData(data:RoleLogData):Void {
		if (data == null) {
			this.alpha = 0.5;
			this.nameLabel.visible = this.numbers.visible = this.head.visible = this.value4.visible = false;
			return;
		}
		this.alpha = 1;
		this.nameLabel.visible = this.numbers.visible = this.head.visible = this.value4.visible = true;
		if (GameWorld.currentWorld != null) {
			var bitmapData = GameWorld.currentWorld.assets.getBitmapData(data.id);
			this.head.shader = new HeadShader(bitmapData);
		} else {
			// 异步加载
			new BitmapDataFuture("assets/icons/roles/" + data.id + ".png").onComplete(bitmapData -> {
				this.head.shader = new HeadShader(bitmapData);
			});
		}
		// 玩家昵称
		var roleData = XlsData.roles.getDataByRoleid(data.id);
		if (roleData != null)
			this.nameLabel.data = roleData.name; // 连击数
		this.value1.data = Std.string(data.data.getMaxValue(MAX_ATTACK_TIMES));
		// // 秒伤
		this.value2.data = Std.string(Std.int(data.data.getAvgValue(TOTAL_ATTACK_DAMAGE) / Math.max(1, data.data.getAvgValue(ATTACK_TIME))));
		// // 连段伤害
		this.value3.data = Std.string(data.data.getMaxValue(MAX_ATTACK_DAMAGE));
		// // 总评
		this.value4.data = Std.string(Std.int(data.data.getAvgScrore() * 10) / 10);
	}
}
